{include file="public/head"}
<style type="text/css" media="screen">
    .x-body {
        min-width: 1100px;
    }

    body {
        overflow-x: scroll;
    }
    .x-right button{
        display: initial;
    }
</style>
<body>
<div class="x-body">
    <div class="lotus-nav">
        {if $info.manual == 1}
            <button class="layui-btn layui-btn-sm"
                    onclick="x_admin_show('新建货运方式','addShip.html?logistics_id={$Think.get.id}',500)">
                <i class="layui-icon layui-icon-add-circle"></i>新建
            </button>
            <button class="layui-btn layui-btn-sm layui-btn-primary" onclick="forbidden('{$Think.get.id}')">
                <i class="layui-icon layui-icon-unlink"></i>禁用
            </button>
            <button class="layui-btn layui-btn-sm layui-btn-danger" onclick="delAll('{$Think.get.id}')">
                <i class="layui-icon"></i>批量删除
            </button>
        {else/}
            <div class="layui-input-inline layui-form">
                <select name="nid" id="nid" lay-filter="nid" lay-search>
                    <option value="">支持国家</option>
                    {volist name="nation" id="vo"}
                    <option value="{$vo.id}" title="{$vo.short}" {if $Think.get.short eq $vo['short']} selected {/if}>{$vo.name}</option>
                    {/volist}
                </select>
            </div>
            <button class="layui-btn layui-btn-sm layui-btn-primary" onclick="forbidden('{$Think.get.id}')">
                <i class="layui-icon layui-icon-unlink"></i>禁用
            </button>
            <button class="layui-btn layui-btn-sm" onclick="restore('{$info.shipfun}','{$Think.get.id}')">
                <i class="layui-icon layui-icon-auz"></i>初始化
            </button>
            <button class="layui-btn layui-btn-sm layui-btn-danger" onclick="delAll('{$Think.get.id}')">
                <i class="layui-icon"></i>批量删除
            </button>
        {/if}

        <span class="x-right">共有数据:<i class="i_count">{$list->total()}</i>条
            <button onclick="javascript:location.reload()" class="layui-btn-default ">
                <i class="layui-icon layui-icon-refresh"></i>
            </button>
        </span>
    </div>



    <table class="layui-table">
        <thead>
        <tr>
            <th style="width: 50px;text-align:center">
                <div class="header layui-form-checkbox" lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
            </th>
            <th style="text-align:center">运输方式简称</th>
            <th>运输方式中文名称</th>
            <th>支持国家</th>
            <th style="width:80px;text-align:center">送达时间(天)</th>
            <th style="width:70px;text-align:center">是否可追踪</th>
            <th style="width:60px;text-align:center">是否称重</th>
            <th style="width:50px;text-align:center">状态</th>
            {if $info.manual == 1}
            <th style="width: 135px;text-align:center">操作</th>
            {else/}
            <th style="width: 85px;text-align:center">操作</th>
            {/if}
        </tr>
        </thead>
        <tbody>
        {volist name="list" id="vo"}
        <tr>
            <td style="text-align:center">
                <div class="layui-form-checkbox" lay-skin="primary" data-id='{$vo.id}'>
                    <i class="layui-icon">&#xe605;</i>
                </div>{$i}
            </td>
            <td style="text-align:center">{$vo.method_code}</td>
            <td>{$vo.cn_name}</td>
            <td>{$vo.nation}</td>
            <td style="text-align:center">{$vo.deliverytime}</td>
            <th style="text-align:center">
                {switch name="vo.iftracking" }
                {case value="1"}<b style="color: #5FB878">是</b>{/case}
                {case value="2"}<b style="color: red">否</b>{/case}
                {/switch}
            </th>
            <th style="text-align:center">
                {switch name="vo.is_weight" }
                {case value="1"}<b style="color: #5FB878">是</b>{/case}
                {case value="2"}<b style="color: red">否</b>{/case}
                {/switch}
            </th>
            <th style="text-align:center">
                {switch name="vo.type" }
                {case value="1"}<b style="color: #5FB878">启用</b>{/case}
                {case value="2"}<b style="color: red">禁用</b>{/case}
                {/switch}
            </th>
            <td style="text-align:center">
                {if $info.manual == 1}
                <button class="layui-btn layui-btn-xs"
                        onclick="x_admin_show('编辑货运方式','editShip.html?id={$vo.id}',500)">
                    编辑
                </button>
                {/if}
                {if $vo.type == 1}
                <button onclick="updateType(2,'{$vo.id}','{$Think.get.id}')" class="layui-btn layui-btn-xs layui-btn-primary">禁用</button>
                {else/}
                <button onclick="updateType(1,'{$vo.id}','{$Think.get.id}')" class="layui-btn layui-btn-xs layui-btn-normal">启用</button>
                {/if}
                <button onclick="del(this,'{$vo.id}','{$Think.get.id}')" class="layui-btn layui-btn-xs layui-btn-danger">
                    删除
                </button>
            </td>
        </tr>
        {/volist}
        </tbody>
    </table>
    <div class="page">
        <div>
            {$list->render()}
        </div>
    </div>
</div>
</body>
{include file="public/foot"}
<script>
    var form = layui.form;
    form.on('select(nid)', function (data) {
        location.href = 'listShip.html?id={$Think.get.id}&short='+data.elem[data.elem.selectedIndex].title;
    });

    //初始化
    function restore(fun,id) {
        var nid = $("#nid").val();
        if(nid == ''){
            layer.msg('请先选择国家');
            return false;
        }
        layer.confirm('确认还原初始数据？', function (index) {
            layer.load(1);
            $.post("{:url('admin/logistics/restore')}", {
                id: id,
                nid: nid,
                fun:fun
            }, function (data) {
                layer.closeAll('loading');
                if (data.code == 1) {
                    layer.msg(data.msg, {icon: 1, time: 1000}, function () {
                        location.reload();
                    });
                } else {
                    layer.msg(data.msg, {icon: 2, time: 1000});
                }

            });
        });
    }

    //禁用
    function updateType(type, id, logistics_id) {
        if (type == 1) {
            var con = '启用';
        } else {
            var con = '禁用';
        }
        layer.confirm('确认要' + con + '此运输方式？', function (index) {
            layer.load(1);
            $.post("{:url('admin/logistics/updateType')}", {
                type: type,
                id: id,
                logistics_id: logistics_id
            }, function (data) {
                layer.closeAll('loading');
                if (data.code == 1) {
                    layer.msg(data.msg, {icon: 1, time: 1000}, function () {
                        location.reload();
                    });
                } else {
                    layer.msg(data.msg, {icon: 2, time: 1000});
                }

            });
        });
    }
    
    //批量禁用
    function forbidden(logistics_id) {
        var data = tableCheck.getData();
        if (data.length == 0) {
            layer.msg("请选择需要禁用的货运方式");
            return false;
        }
        layer.confirm('确认要全部禁用吗？', function (index) {
            layer.load(1);
            $.post("{:url('admin/logistics/forbiddenShip')}", {
                id: data,
                logistics_id: logistics_id
            }, function (data) {
                layer.closeAll('loading');
                if (data.code == 1) {
                    layer.msg(data.msg, {icon: 1, time: 1000}, function () {
                        location.reload();
                    });
                } else {
                    layer.msg(data.msg, {icon: 2, time: 1000});
                }

            });
        });
    }
    
    //删除所有
    function delAll(logistics_id) {
        var data = tableCheck.getData();
        if (data.length == 0) {
            layer.msg("请选择需要删除的货运方式");
            return false;
        }
        layer.confirm('确认要全部删除吗？', function (index) {
            layer.load(1);
            $.post("{:url('admin/logistics/delShip')}", {
                id: data,
                logistics_id: logistics_id
            }, function (data) {
                layer.closeAll('loading');
                if (data.code == 1) {
                    layer.msg(data.msg, {icon: 1, time: 1000}, function () {
                        location.reload();
                    });
                } else {
                    layer.msg(data.msg, {icon: 2, time: 1000});
                }

            });
        });
    }

    function del(obj, id, logistics_id) {
        var count = $(".i_count")[0].innerText;
        layer.confirm('确认要删除吗？', function (index) {
            layer.load(1);
            $.post("{:url('admin/logistics/delShip')}", {
                id: id,
                logistics_id: logistics_id
            }, function (data) {
                layer.closeAll('loading');
                if (data.code == 1) {
                    layer.msg(data.msg, {icon: 1, time: 1000}, function () {
                        $(obj).parents('tr').remove();
                        $(".i_count").html(count - 1);
                    });
                } else {
                    layer.msg(data.msg, {icon: 2, time: 1000});
                }

            });
        });
    }
</script>
